<?php

namespace App\Http\Controllers;

use App\Box;
use App\Mail\NewUser;
use App\Product;
use App\Shop;
use App\Student;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Mail;

class ShopController extends Controller
{
    public function index() {
        $shop = Shop::find(1);
        dd($shop->getAttributes());
        dd($shop->name_id);
        /** Shop $shop */
        foreach ($shop->products() as $product) {
            dd($product->name);
        }
    }

    public function test()
    {
        $string = '{"description":"","visits":[{"contact_type":"Contacts","contact_id":"5a6941dc-888f-49bf-9225-50bd31b6ed48","contact_name":"\u753b\u800c1\u533b\u751f","description":"\u8054\u7edc\u5173\u7cfb","category":1,"category_desc":"\u65e5\u5e38\u62dc\u8bbf"}]}';
        $visit = json_decode($string);
        $res = data_get($visit, 'visits');
        dd($res);
    }

    public function lang()
    {
        $res = Lang::has('active_url');
        dd($res);
    }

    /**
     * pluck
     */
    public function plk()
    {
        $collection = collect(
            [
                ['product_id' => 'prod_100', 'name' => 'desk', 'price' => 100],
                ['product_id' => 'prod_101', 'name' => 'chair', 'price' => 120],
            ]
        );

        $plucked = $collection->pluck('name')->all();
    }

    public function box()
    {
        $box = new Box(['team', 'terry', 'skip', 'hello', 'thomas', 'apple']);
        $res = $box->startWith('t');
        return ($res);
    }

    /**
     * show scope
     */
    public function showSco()
    {
        $res = Product::expensive()->get();
        return $res;
    }

    public function searchMany()
    {
        $shop = Shop::with(['products' => function($query) {
            $query->where('price', '>', 20);
        }])
            ->where('id', '>', 1 )->get();
        dd($shop);
        return $shop;

    }

    public function au()
    {
        dd(Auth::user());
    }

    public function add()
    {
       return Shop::create(
            [
                'name' => 'yves rocher'
            ]
        );
    }
    public function sendMail()
    {
        $student = Student::create(
            [
                'name' => 'li si',
                'password' => bcrypt(88888888)
            ]
        );
        event(new \App\Events\NewUser($student));

    }
    
    public function service()
    {
        app()->make('Shop');
    }
    
    public function getFirst()
    {
       dd(4545 ,Shop::first(), 12122222);
    }
}
